home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / examples / blitrsnd / part01
Encoding:
Internet Message Format  |  1990-08-15  |  42.5 KB

  1. Path: abcfd20.larc.nasa.gov!amiga-request
  2. From: amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v90i225: BlitterSand - cellular automaton model of self organized criticality, Part01/01
  4. Reply-To: michael creutz <creutz@max.bnl.gov>
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga:v90i225@abcfd20.larc.nasa.gov>
  7. Date: 15 Aug 90 01:04:37 GMT
  8. Approved: tadguy@uunet.UU.NET (Tad Guy)
  9. X-Mail-Submissions-To: amiga@uunet.uu.net
  10. X-Post-Discussions-To: comp.sys.amiga
  11.  
  12. Submitted-by: michael creutz <creutz@max.bnl.gov>
  13. Posting-number: Volume 90, Issue 225
  14. Archive-name: examples/blittersand/part01
  15.  
  16. [ uuencoded executable and icons enclosed  ...tad ]
  17.  
  18. This program simulates the cellular automaton model presented
  19. by P. Bak, C. Tang, and K. Wiesenfeld (Phys. Rev. Lett. 59, 381 (1987);
  20. Phys. Rev. A38, 364 (1988)) to illustrate self organized criticality.
  21. Each site carries a positive integer representing the local slope of 
  22. a sandpile.  If the slope exceeds 3, the site is unstable and on
  23. updating it drops by 4, adding one to each of his neighbors.
  24. Sand is lost only at the edges.  Any state will relax to stability
  25. through such sand loss.
  26.  
  27. #!/bin/sh
  28. # This is a shell archive.  Remove anything before this line, then unpack
  29. # it by saving it into a file and typing "sh file".  To overwrite existing
  30. # files, type "sh file -c".  You can also feed this as standard input via
  31. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  32. # will see the following message at the end:
  33. #        "End of archive 1 (of 1)."
  34. # Contents:  BlitterSan0.uu BlitterSan1.uu BlitterSand.asm
  35. #   BlitterSand.uu
  36. # Wrapped by tadguy@abcfd20 on Tue Aug 14 21:04:35 1990
  37. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  38. if test -f 'BlitterSan0.uu' -a "${1}" != "-c" ; then 
  39.   echo shar: Will not clobber existing file \"'BlitterSan0.uu'\"
  40. else
  41. echo shar: Extracting \"'BlitterSan0.uu'\" \(3658 characters\)
  42. sed "s/^X//" >'BlitterSan0.uu' <<'END_OF_FILE'
  43. Xbegin 700 BlitterSand.asm.info
  44. XMXQ```0``````8P`+`&(`'0`&``,``0`C,C``(SB0````````````````````;
  45. XM````!"(`(SKX`````````%\```````````````````````````!B`!T``P`!=
  46. XM.*C_`````````````````````````````````$5555550```````````15_5Q
  47. XM555```````````!%5M55544``````````$569]?51P``````````159G9V5'3
  48. XM``````````!%5F9F14<``````````$56QF9U1P``````````15_'Q\5'````T
  49. XM``````!%5!4%!4<``````````$5555551P``````````1?UU=55'````````G
  50. XM``!%S%%Q54<``````````$7$=7%]1P``````````1?5Q<<U'``````````!%7
  51. XMP7%Q_$<``````````$7%<7'`1P``````````1>5Y>7U'``````````!%!4%!%
  52. XM04<``````````$5555551P``````````1555555'``````````!%555554<`H
  53. XM`````````$5555551P``````````15550`%'``````````!%555554<`````W
  54. XM````````````!P``````````+_______```````````55555554`````````O
  55. XM```````````````````!_______X``````````'_______@``````````?_P8
  56. XM?____\`````````!__D_____P`````````'_^9P\/_O``````````?_YF9F?&
  57. XM^\`````````!__F9F?_[P`````````'_^3F9G_O``````````?_P?#P_^\``G
  58. XM```````!_______[P`````````'_______O``````````?X#SX__^\``````(
  59. XM```!_S/_S__[P`````````'_/X_/A_O``````````?\/S\\S^\`````````!V
  60. XM_S_/SP/[P`````````'_/\_//_O``````````?X?AX>'^\`````````!____=
  61. XM___[P`````````'_______O``````````?______^\`````````!_______[>
  62. XMP`````````'_______O``````````?______^\`````````!_______[P```E
  63. XM``````'_______O``````````?@``````\``````````________P```````M
  64. XM``!________`````````````````````````````````````````````````Z
  65. XM`````````````````````````````````````````````````````````````
  66. XM`````````````````````````````````````````````````````````````
  67. XM`````````````````````````````````````````````````````````````
  68. XM`````````````````````````````````````````````````````````````
  69. XM`````````````````````````````````````````````````````````````
  70. XM`````````````````````````````````````````````````````````````
  71. XM`````````````````````````````````````````````````````````````
  72. XM`````````````````````````````````````````````````````````````
  73. XM`````````````````````&(`'0`#``(2</\`````````````````````````%
  74. XM*JJJJJJH!5555555```W______Z_______L``#?______K______^P``-___K
  75. XM___^O______[```WZJJJJN`#ZJJJJKL``#?______K______^P``-______^O
  76. XMOZJJJJJ[```W______Z_______L``#?55555?K^JJJJJNP``-______^O___B
  77. XM___[```W555557Z_JJJJJKL``#?______K______^P``-U55555^OZJJJJJ[V
  78. XM```W_____^`#______L``#=55555?K^JJJJJNP``-______^O______[```W6
  79. XMU55557Z_JJJJJKL``#?______K______^P``-U55555^OZJJJJJ[```W____Z
  80. XM__Z_______L``#=55555?K^JJJJJNP``-______^O______[```W_____^`#;
  81. XM______L``#?__U___K___K__^P``-______^O______[```P``````"`````4
  82. XM``,``"JJJJJJJ`55555550````````````````````#_______X?_______`^
  83. XM`/_______________\``^``````!P``````'P`#X``````'```````?``/@`L
  84. XM`````<``````!\``^``````?_!55555'P`#X``````'```````?``/@`````N
  85. XM`<!555551\``^``````!P``````'P`#X*JJJJH'`555554?``/@``````<``1
  86. XM````!\``^*JJJJJ!P%55555'P`#X``````'```````?``/BJJJJJ@<!55555X
  87. XM1\``^``````?_``````'P`#XJJJJJH'`555554?``/@``````<``````!\``=
  88. XM^"JJJJJ!P%55555'P`#X``````'```````?``/BJJJJJ@<!555551\``^```P
  89. XM```!P``````'P`#XJJJJJH'`555554?``/@``````<``````!\``^``````?;
  90. XM_``````'P`#X``"@``'```%```?``/@``````<``````!\``____________;
  91. XM____P`#________________``/_______A_______\``````````````````$
  92. XM`````````````````````````````````````````````````````````````
  93. XM`````````````````````````````````````````````````````````````
  94. XM`````````````````````````````````````````````````````````````
  95. XM`````````````````````````````````````````````````````````````
  96. XM`````````````````````````````````````````````````````````````
  97. XM`````````````````````````````````````````````````````````````
  98. XM`````````````````````````````````````````````````````````````
  99. XM`````````````````````````````````````````````````````````````
  100. XM`````````````````````````````````````````````````!-S>7,Z=71I^
  101. X,;&ET:65S+VUO<F4`L
  102. X``
  103. Xend
  104. Xsize 2577
  105. END_OF_FILE
  106. if test 3658 -ne `wc -c <'BlitterSan0.uu'`; then
  107.     echo shar: \"'BlitterSan0.uu'\" unpacked with wrong size!
  108. fi
  109. # end of 'BlitterSan0.uu'
  110. fi
  111. if test -f 'BlitterSan1.uu' -a "${1}" != "-c" ; then 
  112.   echo shar: Will not clobber existing file \"'BlitterSan1.uu'\"
  113. else
  114. echo shar: Extracting \"'BlitterSan1.uu'\" \(1204 characters\)
  115. sed "s/^X//" >'BlitterSan1.uu' <<'END_OF_FILE'
  116. Xbegin 700 BlitterSand.info
  117. XMXQ```0``````%``+`#\`%@`&``$``0`C(\@`(R<P``'SG@```````````&0`N
  118. XM`````R(``````"`'F````!```````````````````!`````````_`!8``@``;
  119. XM_K@#````````````````````````````````````(`````````!_````````8
  120. XM``'X```````````````````````J@````````$!`````````@"````,```$`'
  121. XM```*!````````!4(`````%`HJI````"JH%%58````%5:HJJJ@```*K5%554`@
  122. XM```52@JJJJ@```J4555550`"JJB*JJBJH!5544555%50*JJJHJJJ*JA55555Y
  123. XM55555`````````````````````````````'@`````````_\````````'`?@`V
  124. XM``````8`.```````!P!P`!4````#`<``H(````'_``$`0````P`````@``H$@
  125. XM```!`?``%0@```'_H"BND````%505=_@````*JJJO_^```!5555__P```"JJ;
  126. XMJO_^J```%555?_U5``*JJJK_^JJ@%55555_555`JJJJJJJJJJ%5555555554$
  127. XM```````_`!8``@`!`!@#``````````````````````````````JJH```````'
  128. XM555`````<`"JJH````!P`5557__\`'`"JJJ@````<`%554````!P`*JJH```(
  129. XM````U55```````&`0``*`````!```!4``````%`HJH````"JH%%50````E5:=
  130. XMHJJB@``$*K5%55$```(5:@JJJJ@``$J4555150`"JJB*JJBJH!5544555%50Y
  131. XM*JJJHJJJ*JA5555555555```````````````````````'__@``'_\`#__^``Y
  132. XM`X!P`?O_P``'`'`#U_____X`<`.J_^``!X!P`]7_X``'P'``JO_@``'_\`!5I
  133. XM_^```````(````H````!$_``%0````'_H"BJ@````550555````"JJJJJJJ`8
  134. XM``15555570```BJJJJJNJ```55555555``*JJJJJKJJ@%555555555`JJJJJ@
  135. X0JJJJJ%5555555554````!```1
  136. X``
  137. Xend
  138. Xsize 826
  139. END_OF_FILE
  140. if test 1204 -ne `wc -c <'BlitterSan1.uu'`; then
  141.     echo shar: \"'BlitterSan1.uu'\" unpacked with wrong size!
  142. fi
  143. # end of 'BlitterSan1.uu'
  144. fi
  145. if test -f 'BlitterSand.asm' -a "${1}" != "-c" ; then 
  146.   echo shar: Will not clobber existing file \"'BlitterSand.asm'\"
  147. else
  148. echo shar: Extracting \"'BlitterSand.asm'\" \(29043 characters\)
  149. sed "s/^X//" >'BlitterSand.asm' <<'END_OF_FILE'
  150. X;BlitterSand 
  151. X;by Mike Creutz
  152. X;   P.O. Box 204
  153. X;   E. Moriches, NY 11940
  154. X;   USA
  155. X;creutz@bnlux0.bnl.gov
  156. X;23 June 1990 
  157. X
  158. X;This program simulates the cellular automaton model presented
  159. X;by P. Bak, C. Tang, and K. Wiesenfeld (Phys. Rev. Lett. 59, 381 (1987);
  160. X;Phys. Rev. A38, 364 (1988)) to illustrate self organized criticality.
  161. X;Each site carries a positive integer representing the local slope of 
  162. X;a sandpile.  If the slope exceeds 3, the site is unstable and on
  163. X;updating it drops by 4, adding one to each of his neighbors.
  164. X;Sand is lost only at the edges.  Any state will relax to stability
  165. X;through such sand loss.
  166. X
  167. X;The colors representing slopes of 0 through 7 are white, black,
  168. X;red, green, yellow, blue, magenta, and cyan, respectively.
  169. X
  170. X;Various keypresses do as follows:
  171. X;     <esc>, q, or any control character exits
  172. X;     p     pauses; repeated presses single step; any other key restarts
  173. X;     d     doubles the lattice modulo 8
  174. X;     a     sets a flag to pause after each relaxation
  175. X
  176. X;The program can be run from either CLI or Workbench.  This code
  177. X;is completely self contained and will run directly through A68K 
  178. X;followed by BLink without need for any include files. 
  179. X
  180. X;The program directly accesses the blitter for speed, but does
  181. X;so in a mode friendly to multitasking.  To understand the program 
  182. X;details you should have the Amiga Hardware Reference Manual.  
  183. X
  184. X;Technically, the show proceeds as follows:
  185. X;We start with ones on the borders and twos on the corners
  186. X;of a 288 by 188 lattice.  For the first loop, whenever a stable state 
  187. X;occurs, the heights are all doubled, and the system is allowed to 
  188. X;relax back to stability.  This eventually leads to a unique state 
  189. X;that when doubled relaxes to itself.  The system can be described 
  190. X;as a large Abelian group and this state represents the identity.
  191. X
  192. X;After the identity is found, the program proceeds to construct
  193. X;the inverse of the state with all cells unity.  After this is found it
  194. X;is tripled to give the inverse of the minimally stable state with all 
  195. X;cells being 3.
  196. X
  197. X;After all this, to keep the show going, the identity is 
  198. X;added to the system which then relaxes back to itself.  This loops
  199. X;until intervention.
  200. X
  201. X;If you hit 'd' on an active state early in the program, the search for
  202. X;the identity will be derailed and the program will go into a mode where
  203. X;the pattern is unlikely to repeat for the lifetime of the universe. 
  204. X;After a few hours, however, it will probably look uninterestingly random.
  205. X; ******************************************************
  206. X
  207. X; library offsets:
  208. X_LVOOpenLibrary EQU -552
  209. X_LVOCloseLibrary EQU -414 
  210. X_LVOSetAPen EQU -342 
  211. X_LVOSetBPen EQU -348 
  212. X_LVOSetDrMd EQU -354 
  213. X_LVOWritePixel EQU -324 
  214. X_LVOMove EQU -240
  215. X_LVODraw EQU -246
  216. X_LVOText EQU -60
  217. X_LVOClipBlit EQU -552 
  218. X_LVOOpenScreen EQU -198 
  219. X_LVOOpenWindow EQU -204 
  220. X_LVOCloseScreen EQU -66 
  221. X_LVOCloseWindow EQU -72
  222. X_LVOGetMsg EQU -372 
  223. X_LVOReplyMsg EQU -378 
  224. X_LVOWaitPort EQU -384 
  225. X_LVOLoadRGB4 EQU -192 
  226. X_LVOOwnBlitter EQU -456 
  227. X_LVODisownBlitter EQU -462 
  228. X_LVOWaitBlit EQU -228 
  229. X_LVOAllocMem EQU -198 
  230. X_LVOFreeMem EQU -210 
  231. X_LVOSetRast EQU -234
  232. X_LVOFindTask EQU -294 
  233. X_LVOForbid EQU -132 
  234. X
  235. X;IDCMP Flags 
  236. XCLOSEWINDOW EQU $200
  237. XVANILLAKEY  EQU $200000
  238. X; window flags
  239. XWINDOWDRAG  EQU $2
  240. XWINDOWDEPTH EQU $4      
  241. XWINDOWCLOSE EQU $8
  242. XBACKDROP    EQU $100 
  243. XBORDERLESS  EQU $800
  244. XACTIVATE    EQU $1000
  245. X; various useful numbers
  246. XMEMF_PUBLIC EQU 1
  247. XMEMF_CHIP   EQU 2
  248. XMEMF_FAST   EQU 4
  249. XMEMB_CLEAR  EQU $10000
  250. Xpr_CLI      EQU 172
  251. Xpr_MsgPort  EQU 92
  252. XAbsExecBase EQU $4
  253. XJAM1        EQU 0
  254. XJAM2        EQU 1
  255. XCOMPLEMENT  EQU 2
  256. XINVERSID    EQU 3
  257. X
  258. X; custom chip register offsets
  259. X_custom EQU $DFF000
  260. XDMACONR EQU $002
  261. XBLTCON0 EQU $040
  262. XBLTCON1 EQU $042
  263. XBLTAFWM EQU $044
  264. XBLTALWM EQU $046
  265. XBLTCPT  EQU $048
  266. XBLTBPT  EQU $04C
  267. XBLTAPT  EQU $050
  268. XBLTDPT  EQU $054
  269. XBLTSIZE EQU $058
  270. XBLTCMOD EQU $060
  271. XBLTBMOD EQU $062
  272. XBLTAMOD EQU $064
  273. XBLTDMOD EQU $066
  274. XBLTCDAT EQU $070
  275. XBLTBDAT EQU $072
  276. XBLTADAT EQU $074
  277. X
  278. X; various size parameters
  279. Xxmin EQU 16  ; should be a multiple of 16
  280. Xymin EQU 11  ; 11 or more to avoid border effects
  281. Xxmax EQU 303 ; -1+multiple of 16
  282. Xymax EQU 198  
  283. X
  284. X; a small system for testing:
  285. X;xmin equ 48
  286. X;xmax equ 127
  287. X;ymin equ 50
  288. X;ymax equ 150  
  289. X
  290. Xstartdisp EQU 2*(xmin/16)+ymin*40 ; shift from start of bitplane to lattice
  291. Xmodulo    EQU 40-2*((xmax-xmin+1)/16) ; blitter modulo
  292. Xenddisp   EQU -modulo-2+((ymax-ymin+1)*40)      ; shift to end of lattice
  293. Xbsize     EQU 20-(modulo/2)+$40*(ymax-ymin+1)   ; for BLTSIZE
  294. Xworkspacesize EQU 40*(ymax-ymin+1)
  295. X
  296. X ; startup code for CLI or Workbench
  297. X ; opens graphics and intuition libraries, calls 'Main' and exits
  298. Xstartup:
  299. X  movem.l d2-d7/a2-a6,-(a7) ; save registers
  300. X  move.l AbsExecBase,a6     ; exec base pointer
  301. X  clr.l workbenchmessage
  302. X  suba.l a1,a1              ; clear a1
  303. X  jsr _LVOFindTask(a6)      ; where is our task
  304. X  move.l d0,a4
  305. X  tst.l pr_CLI(a4)          ; are we running from CLI?
  306. X  bne fromcli               ; if not then get workbench message
  307. X  lea pr_MsgPort(a4),a0
  308. X  jsr _LVOWaitPort(a6)
  309. X  Jsr _LVOGetMsg(a6)
  310. X  move.l d0,workbenchmessage ; save for exit
  311. X;open graphics and intuition libraries
  312. Xfromcli  lea GraphicsName(pc),a1  ; pointer to name of library
  313. X    moveq #0,d0         ; accept any version
  314. X    jsr _LVOOpenLibrary(a6)
  315. X    move.l d0,GraphicsBase    ; save graphics base
  316. X    tst.l d0
  317. X    beq.s Exit1          ; quit if trouble opening library
  318. X  lea IntuitionName(pc),a1  ; pointer to name of library
  319. X    moveq #0,d0         ; accept any version
  320. X    jsr _LVOOpenLibrary(a6)
  321. X    move.l d0,IntuitionBase ; save intuition base
  322. X    tst.l d0
  323. X    beq.s Exit2          ; quit if trouble opening library
  324. X
  325. X; execute main program
  326. X    bsr Main          
  327. X
  328. X;final cleanup
  329. XExit3: movea.l IntuitionBase,a1    ; intuition base
  330. X       movea.l AbsExecBase,a6      ; exec base pointer
  331. X       jsr _LVOCloseLibrary(a6)
  332. XExit2: movea.l GraphicsBase,a1     ; graphics base
  333. X       jsr _LVOCloseLibrary(a6)
  334. X       moveq.l #0,d0               ; return zero
  335. XExit1: tst.l workbenchmessage ; are we a workbench program?
  336. X       beq.s Exit0            ; if not goto exit0
  337. X         jsr _LVOForbid(a6)     ; because the RKM tells me so
  338. X         movea.l workbenchmessage(pc),a1
  339. X         jsr _LVOReplyMsg(a6)   ; reply to workbench message
  340. XExit0: movem.l (a7)+,d2-d7/a2-a6   ; restore registers
  341. X       rts ; end of startup code
  342. X
  343. XMain: move.l a7,oldstack ; save stack for exit
  344. X; allocate various working areas
  345. X   moveq.l #7,d2 ; memory allocation loop counter
  346. X   lea.l workingplane1(pc),a2
  347. X   bra.s startalloc
  348. Xallocloop move.l #workspacesize,d0 ; size for working area
  349. X          move.l #MEMF_CHIP+MEMB_CLEAR,d1  ;get chip memory 
  350. X          jsr _LVOAllocMem(a6)
  351. X          tst.l d0
  352. X          beq quit1
  353. X           move.l d0,(a2)+        
  354. Xstartalloc dbf.s d2,allocloop
  355. X
  356. X; open screen and window
  357. X     move.l IntuitionBase(pc),a6
  358. X     lea myscreen(pc),a0
  359. X     jsr _LVOOpenScreen(a6) ; open custom screen
  360. X       move.l d0,screen     ; save screen structure pointer
  361. X       beq quit1            ; quit if trouble
  362. X     lea mywindow(pc),a0    ; open display window
  363. X     jsr  _LVOOpenWindow(a6) 
  364. X       move.l d0,window     ; save address of window structure
  365. X       beq quit2            ;quit if trouble
  366. X       movea.l d0,a0
  367. X       move.l 86(a0),userport
  368. X       movea.l 50(a0),a0 ; rastport
  369. X       move.l a0,rastport
  370. X       move.l 4(a0),a0 ; bitmap structure
  371. X       move.l 8(a0),bitplane1
  372. X       move.l 12(a0),bitplane2
  373. X       move.l 16(a0),bitplane3
  374. X       addi.l #startdisp,bitplane1
  375. X       addi.l #startdisp,bitplane2
  376. X       addi.l #startdisp,bitplane3
  377. X;set colors
  378. X     movea.l GraphicsBase(pc),a6          ; graphics library address in a6
  379. X     movea.l screen(pc),a0
  380. X     adda.l #44,a0      ; viewport
  381. X     lea.l colors(pc),a1
  382. X     moveq.l #8,d0
  383. X     jsr _LVOLoadRGB4(a6)   
  384. X; show credits
  385. X     bsr credits      
  386. X;draw initial box of ones
  387. X     movea.l rastport(pc),a1    
  388. X     moveq.w #1,d0
  389. X     jsr _LVOSetAPen(a6) ; set pen color
  390. X       movea.l rastport(pc),a1    
  391. X       moveq.w #JAM1,d0
  392. X     jsr _LVOSetDrMd(a6) ; set drawing mode      
  393. X       movea.l rastport(pc),a1    
  394. X       move.w #xmin,d0
  395. X       move.w #ymin,d1
  396. X     jsr _LVOMove(a6) ; go to top left corner
  397. X       movea.l rastport(pc),a0    
  398. X       move.w #xmax,d0
  399. X       move.w #ymin,d1
  400. X     jsr _LVODraw(a6) ; draw top line
  401. X       movea.l rastport(pc),a0    
  402. X       move.w #xmax,d0
  403. X       move.w #ymax,d1
  404. X     jsr _LVODraw(a6) ; right side
  405. X       movea.l rastport(pc),a0    
  406. X       move.w #xmin,d0
  407. X       move.w #ymax,d1
  408. X     jsr _LVODraw(a6) ; bottom
  409. X       movea.l rastport(pc),a0    
  410. X       move.w #xmin,d0
  411. X       move.w #ymin,d1
  412. X     jsr _LVODraw(a6) ; left
  413. X;set corners to two
  414. X       movea.l rastport(pc),a1    
  415. X       moveq.w #2,d0
  416. X     jsr _LVOSetAPen(a6) ; new color for corners
  417. X       movea.l rastport(pc),a1    
  418. X       move.w #xmin,d0
  419. X       move.w #ymin,d1
  420. X     jsr _LVOWritePixel(a6) ; nw corner
  421. X       movea.l rastport(pc),a1    
  422. X       move.w #xmax,d0
  423. X       move.w #ymin,d1
  424. X     jsr _LVOWritePixel(a6) ; ne corner
  425. X       movea.l rastport(pc),a1    
  426. X       move.w #xmax,d0
  427. X       move.w #ymax,d1
  428. X     jsr _LVOWritePixel(a6) ; se corner
  429. X       movea.l rastport(pc),a1    
  430. X       move.w #xmin,d0
  431. X       move.w #ymax,d1
  432. X     jsr _LVOWritePixel(a6) ; sw corner
  433. X
  434. X; showtime -- first double until identity found
  435. Xfirstloop: bsr relax
  436. X        lea.l storage1(pc),a0 ; prepare to compare with storage
  437. X        lea.l bitplane1(pc),a1
  438. X        bsr compare2  ; see if lattices equal
  439. X        btst.b #5,control(pc)    
  440. X        bne.s foundidentity
  441. X         lea.l bitplane1(pc),a0
  442. X         lea.l storage1(pc),a1
  443. X         bsr copy2              ; copy bitplanes to storage
  444. X         bsr double             ; double things 
  445. X         bra.s firstloop
  446. X; save identity and set first storage plane to unity
  447. Xfoundidentity:
  448. X         lea.l bitplane1(pc),a0
  449. X         lea.l identity1(pc),a1
  450. X         bsr copy2
  451. X         lea.l storage1(pc),a0
  452. X         bsr set1 
  453. X; subtract first storage plane while adding identity 
  454. X            bra.s stillactive
  455. Xsecondloop: bsr sand
  456. X            btst.b #5,control(pc) ; check if still active   
  457. X            beq.s stillactive
  458. X             lea.l identity1(pc),a0
  459. X             lea.l bitplane1(pc),a1    
  460. X             bsr addit 
  461. Xstillactive: bsr subtract1
  462. X             btst.b #5,control(pc) ; check if more to subtract   
  463. X             bne.s tripleit
  464. X              bsr checkmessage 
  465. X              bra.s secondloop
  466. X; triple to find inverse of minimally stable state
  467. Xtripleit bsr relax 
  468. X         lea.l bitplane1(pc),a0
  469. X         lea.l storage1(pc),a1
  470. X         bsr copy2
  471. X         bsr double 
  472. X         bsr relax
  473. X         lea.l storage1(pc),a0
  474. X         lea.l bitplane1(pc),a1    
  475. X         bsr addit
  476. X         bsr relax
  477. X; to keep display moving, repeatedly add identity and relax
  478. Xfinalloop lea.l identity1(pc),a0
  479. X          lea.l bitplane1(pc),a1    
  480. X          bsr addit
  481. X          bsr relax
  482. X          bra.s finalloop
  483. X
  484. X; time to quit
  485. Xgetout:
  486. X ; close windows and screen 
  487. X      movea.l window(pc),a0
  488. X      move.l IntuitionBase(pc),a6
  489. X      jsr _LVOCloseWindow(a6)
  490. Xquit2 movea.l screen(pc),a0
  491. X      jsr _LVOCloseScreen(a6)
  492. X; deallocate memory
  493. Xquit1: movea.l AbsExecBase,a6
  494. X       moveq.l #7,d2 ; memory deallocation loop counter
  495. X       lea.l workingplane1(pc),a2
  496. X       bra.s startdealloc
  497. Xdeallocloop  move.l #workspacesize,d0 ; size for working area
  498. X             movea.l (a2)+,a1
  499. X             move.l a1,d1        ; to test if not zero
  500. X             beq.s done 
  501. X             jsr _LVOFreeMem(a6) ; return memory
  502. Xstartdealloc dbf.s d2,deallocloop
  503. Xdone movea.l oldstack(pc),a7   ; reset stack pointer
  504. X     rts ; all done
  505. X
  506. X; subroutine to update lattice until relaxed
  507. Xrelax: bsr sand
  508. X       btst.b #5,control(pc) ; check if still active   
  509. X       bne.s relaxed
  510. X        bsr checkmessage 
  511. X        bra.s relax
  512. Xrelaxed: tst.w autopause   ; should we pause
  513. X         beq.s autooff    
  514. X          bsr waitformessage
  515. Xautooff  rts      
  516. X
  517. X; message handling subroutine
  518. X; message location returned in d0, class in d2, code in d3 
  519. X; with VANILLAKEY code is ascii of pressed key 
  520. Xwaitformessage:  ; pause for a signal
  521. X      movea.l AbsExecBase,a6  
  522. X      movea.l userport(pc),a0
  523. X      jsr _LVOWaitPort(a6)   ; wait for a message
  524. Xcheckmessage:   ; enter here to not wait if no message        
  525. X      movea.l AbsExecBase,a6
  526. X      movea.l userport(pc),a0
  527. X      jsr _LVOGetMsg(a6)
  528. X       tst.l d0
  529. X       bne.s messagefound
  530. X        rts
  531. Xmessagefound:
  532. X       movea.l d0,a1       
  533. X       move.l 20(a1),d2    ; save class in d2
  534. X       move.w 24(a1),d3    ; and code in d3
  535. X      jsr _LVOReplyMsg(a6) ; reply to message
  536. X; check for various keypresses
  537. X      cmpi.w #27,d3 ; esc
  538. X       ble getout ; leave for escape or control characters
  539. X      cmpi.w #'q',d3
  540. X       beq getout ; quit for q
  541. X      cmpi.w #'p',d3 ; p ; pause for p
  542. X       bne.s not_p        
  543. X        movea.l userport(pc),a0
  544. X        jsr _LVOWaitPort(a6)   ; wait for a message
  545. Xnot_p cmpi.w #'d',d3 ; d
  546. X       bne.s not_d ; double for d
  547. X        bsr double
  548. Xnot_d cmpi.w #'a',d3 ; a
  549. X       bne.s not_a
  550. X        not.w autopause ; flip autopausing flag
  551. Xnot_a rts  ; continue
  552. X
  553. X; storage area         
  554. X; window and screen parameters
  555. Xmywindow dc.w 0,0,320,200     ; xmin,ymin,xsize,ysize
  556. X         dc.b 0,0             ; detail pen, block pen
  557. X           ; (Intuition Direct Communication Message Port)
  558. X         dc.l VANILLAKEY      ; IDCMP Flags, ask for keypresses 
  559. X         dc.l ACTIVATE+BORDERLESS ;+BACKDROP ; flags (type in amigabasic)
  560. X         dc.l 0               ; gadgets  
  561. X         dc.l 0               ; checkmark
  562. X         dc.l title           ; my title
  563. Xscreen   dc.l 0               ;location of screen, fill later
  564. X         dc.l 0               ;bitmap
  565. X         dc.w 0,0,320,200     ;min-max window size
  566. X         dc.w $f              ; type: 1=wbenchscreen $F=customscreen
  567. Xmyscreen dc.w 0,0,320,200 ;size
  568. X         dc.w 3           ;depth
  569. X         dc.b 5,6         ;pens
  570. X         dc.w $0          ;viewmodes- interlace=4, hires=$8000 
  571. X                          ; sprites=$4000, ham=$800, extra_halfbrite=$80
  572. X         dc.w $f          ;type: customscreen
  573. X         dc.l textattr    ;font
  574. X         dc.l title       ;title
  575. X         dc.l 0           ;gadgets    
  576. X         dc.l 0           ;custombitmap
  577. Xtextattr dc.l fontname
  578. X         dc.w 8   ;fontsize
  579. X         dc.b 0,0    ;style and flags
  580. Xcolors dc.w $fff ; color table
  581. X       dc.w $000 
  582. X       dc.w $f00
  583. X       dc.w $0f0
  584. X       dc.w $ff0
  585. X       dc.w $00f
  586. X       dc.w $f0f
  587. X       dc.w $0ff
  588. X
  589. Xworkbenchmessage dc.l 0
  590. XGraphicsBase     dc.l 0
  591. XIntuitionBase    dc.l 0
  592. XGraphicsName     dc.b 'graphics.library',0
  593. XIntuitionName    dc.b 'intuition.library',0 
  594. Xtitle            dc.b 'BlitterSand -- <esc> to exit',0
  595. Xfontname         dc.b 'topaz.font',0
  596. Xwindow           dc.l 0
  597. Xrastport         dc.l 0
  598. Xuserport         dc.l 0
  599. Xbitplane1        dc.l 0
  600. Xbitplane2        dc.l 0
  601. Xbitplane3        dc.l 0
  602. Xworkingplane1    dc.l 0
  603. Xworkingplane2    dc.l 0
  604. Xworkingplane3    dc.l 0
  605. Xstorage1         dc.l 0
  606. Xstorage2         dc.l 0
  607. Xidentity1        dc.l 0
  608. Xidentity2        dc.l 0
  609. Xcontrol          dc.w 0
  610. Xautopause        dc.w 0
  611. Xoldstack         dc.l 0
  612. X
  613. X; primary updating routine
  614. Xsand: movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  615. X     jsr _LVOOwnBlitter(a6)      ; grab blitter for my use  
  616. X     lea _custom,a5
  617. X     move.l bitplane1(pc),d2     ;start of bitplane1
  618. X     move.l bitplane2(pc),d3     ;start of bitplane2
  619. X     move.l bitplane3(pc),d4     ;start of bitplane3
  620. X     move.l workingplane1(pc),d5 ; start of working plane 1
  621. X     move.l workingplane2(pc),d6 ; start of working plane 2
  622. X     move.l workingplane3(pc),d7 ; start of working plane 3
  623. X ; add left, top, and bottom neighbors to workspace
  624. X ; work on first bit: 
  625. X     jsr _LVOWaitBlit(a6)
  626. X      move.l d5,BLTDPT(a5) ; first workspace plane
  627. X      move.l d4,d0 
  628. X      move.l d0,BLTAPT(a5) ; for left neighbor
  629. X      addi.l #40,d0
  630. X      move.l d0,BLTBPT(a5) ; for bottom neighbor
  631. X      subi.l #80,d0
  632. X      move.l d0,BLTCPT(a5) ; for top
  633. X      move.w #0,BLTCON1(a5)
  634. X      move.w #$1f96,BLTCON0(a5) ; odd number of source bits set
  635. X      move.w #modulo,BLTAMOD(a5)     ; set up modulos
  636. X      move.w #modulo,BLTBMOD(a5)
  637. X      move.w #modulo,BLTCMOD(a5)
  638. X      move.w #modulo,BLTDMOD(a5)
  639. X      move.w #$ffff,BLTAFWM(a5)
  640. X      move.w #$fffe,BLTALWM(a5) ; mask out last bit of row
  641. X      move.w #bsize,BLTSIZE(a5) ; do it
  642. X ; second bit
  643. X     jsr _LVOWaitBlit(a6)
  644. X      move.l d6,BLTDPT(a5) ; second plane of workspace 
  645. X      move.l d4,d0
  646. X      move.l d0,BLTAPT(a5) ; reset bitplane pointers
  647. X      addi.l #40,d0
  648. X      move.l d0,BLTBPT(a5)
  649. X      subi.l #80,d0
  650. X      move.l d0,BLTCPT(a5)
  651. X      move.w #$1fe8,BLTCON0(a5) ; 2 or more source bits set
  652. X      move.w #bsize,BLTSIZE(a5) ; go to it
  653. X; add in fourth neighbor, third bit of result
  654. X     jsr _LVOWaitBlit(a6)
  655. X      move.l d4,d0
  656. X      addi.l #enddisp,d0 
  657. X      move.l d0,BLTAPT(a5) ; end of lattice
  658. X      move.l d7,d0
  659. X      addi.l #enddisp,d0
  660. X      move.l d0,BLTDPT(a5) ; end of third plane of workspace
  661. X      move.l d5,d0
  662. X      addi.l #enddisp,d0
  663. X      move.l d0,BLTBPT(a5) ; first workspace plane
  664. X      move.l d6,d0
  665. X      addi.l #enddisp,d0   ; second workspace plane
  666. X      move.l d0,BLTCPT(a5)
  667. X      move.w #2,BLTCON1(a5) ; descending mode
  668. X      move.w #$1f80,BLTCON0(a5) ; third bit only if all already set
  669. X      move.w #$7fff,BLTALWM(a5)
  670. X      move.w #bsize,BLTSIZE(a5) ; OK
  671. X; add in fourth neighbor, second bit of result
  672. X     jsr _LVOWaitBlit(a6)
  673. X      move.l d4,d0
  674. X      addi.l #enddisp,d0
  675. X      move.l d0,BLTAPT(a5)
  676. X      move.l d6,d0
  677. X      addi.l #enddisp,d0
  678. X      move.l d0,BLTDPT(a5)
  679. X      move.l d0,BLTCPT(a5)
  680. X      move.l d5,d0
  681. X      addi.l #enddisp,d0
  682. X      move.l d0,BLTBPT(a5)
  683. X      move.w #$1f6a,BLTCON0(a5) ; second bit only if appropriate
  684. X      move.w #bsize,BLTSIZE(a5) ; here we go again
  685. X; add in fourth neighbor, first bit of result
  686. X     jsr _LVOWaitBlit(a6)
  687. X      move.l d4,d0
  688. X      addi.l #enddisp,d0
  689. X      move.l d0,BLTAPT(a5)
  690. X      move.l d5,d0
  691. X      addi.l #enddisp,d0
  692. X      move.l d0,BLTDPT(a5)
  693. X      move.l d0,BLTBPT(a5)
  694. X      move.w #$1d3c,BLTCON0(a5) ; second bit from a xor b
  695. X      move.w #bsize,BLTSIZE(a5) ; finish setting up workspace
  696. X; add it all up
  697. X     jsr _LVOWaitBlit(a6) ; 2w,3w,2b to 3b
  698. X      move.l d4,BLTDPT(a5)
  699. X      move.l d3,BLTAPT(a5)
  700. X      move.l d6,BLTBPT(a5)
  701. X      move.l d7,BLTCPT(a5)  
  702. X      move.w #0,BLTCON1(a5) ; reset for ascending mode
  703. X      move.w #$0fea,BLTCON0(a5) 
  704. X      move.w #$ffff,BLTALWM(a5) ; fix last word mask
  705. X      move.w #bsize,BLTSIZE(a5)
  706. X     jsr _LVOWaitBlit(a6) ; 2w,2b to 2b
  707. X      move.l d3,BLTDPT(a5)
  708. X      move.l d3,BLTAPT(a5)
  709. X      move.l d6,BLTBPT(a5)
  710. X      move.w #$0d3c,BLTCON0(a5) 
  711. X      move.w #bsize,BLTSIZE(a5)
  712. X     jsr _LVOWaitBlit(a6) ; 1w,1b,2b to 3w for carry
  713. X      move.l d7,BLTDPT(a5)
  714. X      move.l d2,BLTAPT(a5)
  715. X      move.l d3,BLTBPT(a5)
  716. X      move.l d5,BLTCPT(a5) 
  717. X      move.w #$0f80,BLTCON0(a5) 
  718. X      move.w #bsize,BLTSIZE(a5)
  719. X     jsr _LVOWaitBlit(a6) ; 1w, 1b to 2b
  720. X      move.l d3,BLTDPT(a5)
  721. X      move.l d2,BLTAPT(a5)
  722. X      move.l d5,BLTBPT(a5)
  723. X      move.l d3,BLTCPT(a5) 
  724. X      move.w #$0f6a,BLTCON0(a5) 
  725. X      move.w #bsize,BLTSIZE(a5)
  726. X     jsr _LVOWaitBlit(a6) ; final carry
  727. X      move.l d4,BLTDPT(a5)
  728. X      move.l d4,BLTAPT(a5)
  729. X      move.l d7,BLTBPT(a5)
  730. X      move.w #$0dfc,BLTCON0(a5) 
  731. X      move.w #bsize,BLTSIZE(a5)
  732. X     jsr _LVOWaitBlit(a6) ; 1w, 1b to 1b
  733. X      move.w DMACONR(a5),control ; save control register for later
  734. X      move.l d2,BLTDPT(a5)
  735. X      move.l d2,BLTAPT(a5)
  736. X      move.l d5,BLTBPT(a5)
  737. X      move.w #$0d3c,BLTCON0(a5) 
  738. X      move.w #bsize,BLTSIZE(a5)
  739. X   jsr _LVODisownBlitter(a6) ; I'm done for now
  740. X     rts
  741. X
  742. X; double main lattice
  743. Xdouble: movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  744. X    jsr _LVOOwnBlitter(a6)  
  745. X     lea _custom,a5
  746. X     move.l bitplane1(pc),d2 ;start of bitplane1
  747. X     move.l bitplane2(pc),d3 ;start of bitplane2
  748. X     move.l bitplane3(pc),d4 ;start of bitplane3
  749. X; shift up all bitplanes
  750. X     jsr _LVOWaitBlit(a6)
  751. X      move.l d4,BLTDPT(a5) ; copy to plane 3
  752. X      move.l d3,BLTAPT(a5) ; from plane 2
  753. X      move.w #0,BLTCON1(a5)
  754. X      move.w #$09f0,BLTCON0(a5)
  755. X      move.w #modulo,BLTAMOD(a5)
  756. X      move.w #modulo,BLTBMOD(a5)
  757. X      move.w #modulo,BLTCMOD(a5)
  758. X      move.w #modulo,BLTDMOD(a5)
  759. X      move.w #$ffff,BLTAFWM(a5)
  760. X      move.w #$ffff,BLTALWM(a5)
  761. X      move.w #bsize,BLTSIZE(a5)
  762. X     jsr _LVOWaitBlit(a6)
  763. X      move.l d3,BLTDPT(a5) ; copy to plane 2
  764. X      move.l d2,BLTAPT(a5) ; from plane 1
  765. X      move.w #$09f0,BLTCON0(a5) 
  766. X      move.w #bsize,BLTSIZE(a5)
  767. X     jsr _LVOWaitBlit(a6)
  768. X      move.l d2,BLTDPT(a5) ; clear plane 1
  769. X      move.w #$0100,BLTCON0(a5)
  770. X      move.w #bsize,BLTSIZE(a5)
  771. X     jsr _LVODisownBlitter(a6) ; give it back
  772. X     rts
  773. X
  774. Xcompare2 ; compare two planes, pointed to by (a0) and (a1)
  775. X    movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  776. X     lea _custom,a5
  777. X     move.l (a0)+,d2 ;start of bitplane1
  778. X     move.l (a0),d3 ;start of bitplane2
  779. X     move.l (a1)+,d4 ;start of comparison bitplane1
  780. X     move.l (a1),d5 ;start of comparison bitplane2
  781. X    jsr _LVOOwnBlitter(a6)  ; get blitter
  782. X     jsr _LVOWaitBlit(a6)
  783. X      move.l d2,BLTAPT(a5) ; plane 1
  784. X      move.l d4,BLTBPT(a5) ; compare 1
  785. X      move.w #0,BLTCON1(a5)
  786. X      move.w #$0c3c,BLTCON0(a5)
  787. X      move.w #modulo,BLTAMOD(a5)
  788. X      move.w #modulo,BLTBMOD(a5)
  789. X      move.w #$ffff,BLTAFWM(a5)
  790. X      move.w #$ffff,BLTALWM(a5)
  791. X      move.w #bsize,BLTSIZE(a5)
  792. X     jsr _LVOWaitBlit(a6)
  793. X      move.w DMACONR(a5),control ; save control register for later
  794. X      move.l d3,BLTAPT(a5) ; plane 2
  795. X      move.l d5,BLTBPT(a5) ; compare 2
  796. X      move.w #0,BLTCON1(a5)
  797. X      move.w #$0c3c,BLTCON0(a5)
  798. X      move.w #bsize,BLTSIZE(a5)
  799. X     jsr _LVOWaitBlit(a6)
  800. X      move.w DMACONR(a5),d0
  801. X      and.w d0,control ; save control register for later
  802. X     jsr _LVODisownBlitter(a6) ; give it back
  803. X     rts
  804. X
  805. Xcopy2 ; copy two planes, pointed to by (a0) and (a1)
  806. X    movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  807. X     lea _custom,a5
  808. X     move.l (a0)+,d2 ;start of bitplane1
  809. X     move.l (a0),d3 ;start of bitplane2
  810. X     move.l (a1)+,d4 ;start of copy bitplane1
  811. X     move.l (a1),d5 ;start of copy bitplane2
  812. X    jsr _LVOOwnBlitter(a6)  ; prepare blitter
  813. X     jsr _LVOWaitBlit(a6)
  814. X      move.l d2,BLTAPT(a5) ; plane 1
  815. X      move.l d4,BLTDPT(a5) ; copy 1
  816. X      move.w #0,BLTCON1(a5)
  817. X      move.w #$09f0,BLTCON0(a5) ; straight copy
  818. X      move.w #modulo,BLTAMOD(a5)
  819. X      move.w #modulo,BLTDMOD(a5)
  820. X      move.w #$ffff,BLTAFWM(a5)
  821. X      move.w #$ffff,BLTALWM(a5)
  822. X      move.w #bsize,BLTSIZE(a5)
  823. X     jsr _LVOWaitBlit(a6)
  824. X      move.l d3,BLTAPT(a5) ; plane 2
  825. X      move.l d5,BLTDPT(a5) ; copy 2
  826. X      move.w #0,BLTCON1(a5)
  827. X      move.w #$09f0,BLTCON0(a5)
  828. X      move.w #bsize,BLTSIZE(a5)
  829. X     jsr _LVODisownBlitter(a6) ; give it back
  830. X     rts
  831. X
  832. Xset1: ; set one plane to unity, pointed to by (a0)
  833. X    movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  834. X     lea _custom,a5
  835. X     move.l (a0),d2 ;start of plane
  836. X    jsr _LVOOwnBlitter(a6)  ; get blitter
  837. X     jsr _LVOWaitBlit(a6)
  838. X      move.l d2,BLTDPT(a5) ; plane 1
  839. X      move.w #0,BLTCON1(a5)
  840. X      move.w #$01ff,BLTCON0(a5) ; straight set
  841. X      move.w #modulo,BLTDMOD(a5)
  842. X      move.w #bsize,BLTSIZE(a5)
  843. X     jsr _LVODisownBlitter(a6) ; give it back
  844. X     rts
  845. X
  846. X; subtract storage1 from nonzero lattice sites
  847. Xsubtract1: movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  848. X    jsr _LVOOwnBlitter(a6)
  849. X     lea _custom,a5
  850. X     move.l bitplane1(pc),d2 ;start of bitplane1
  851. X     move.l bitplane2(pc),d3 ;start of bitplane2
  852. X     move.l workingplane1(pc),d5 ; start of working plane 1
  853. X     move.l workingplane2(pc),d6 ; start of working plane 2
  854. X     move.l storage1(pc),d7
  855. X     jsr _LVOWaitBlit(a6)
  856. X      move.l d5,BLTDPT(a5) ; new first plane to working plane
  857. X      move.l d2,BLTAPT(a5) ; old first plane
  858. X      move.l d3,BLTBPT(a5) ; old second plane
  859. X      move.l d7,BLTCPT(a5) ; subtracting plane
  860. X      move.w #0,BLTCON1(a5)
  861. X      move.w #$0f58,BLTCON0(a5)
  862. X      move.w #modulo,BLTAMOD(a5)
  863. X      move.w #modulo,BLTBMOD(a5)
  864. X      move.w #modulo,BLTCMOD(a5)
  865. X      move.w #modulo,BLTDMOD(a5)
  866. X      move.w #$ffff,BLTAFWM(a5)
  867. X      move.w #$ffff,BLTALWM(a5)
  868. X      move.w #bsize,BLTSIZE(a5)
  869. X     jsr _LVOWaitBlit(a6)
  870. X      move.l d6,BLTDPT(a5) ; new second plane to working plane
  871. X      move.l d2,BLTAPT(a5) ; old first plane
  872. X      move.l d3,BLTBPT(a5) ; old second plane
  873. X      move.l d7,BLTCPT(a5) ; subtracting plane
  874. X      move.w #0,BLTCON1(a5)
  875. X      move.w #$0fc4,BLTCON0(a5)
  876. X      move.w #bsize,BLTSIZE(a5)
  877. X     jsr _LVOWaitBlit(a6)
  878. X      move.l d7,BLTDPT(a5) ; new subtracting plane to storage
  879. X      move.l d2,BLTAPT(a5) ; old first plane
  880. X      move.l d3,BLTBPT(a5) ; old second plane
  881. X      move.l d7,BLTCPT(a5) ; subtracting plane
  882. X      move.w #0,BLTCON1(a5)
  883. X      move.w #$0f02,BLTCON0(a5)
  884. X      move.w #bsize,BLTSIZE(a5)
  885. X     jsr _LVOWaitBlit(a6)
  886. X      move.w DMACONR(a5),control ; save control register for later
  887. X      move.l d5,BLTAPT(a5) ; new plane 1
  888. X      move.l d2,BLTDPT(a5) ; copy back
  889. X      move.w #0,BLTCON1(a5)
  890. X      move.w #$09f0,BLTCON0(a5) ; straight copy
  891. X      move.w #bsize,BLTSIZE(a5)
  892. X     jsr _LVOWaitBlit(a6)
  893. X      move.l d6,BLTAPT(a5) ; new plane 2
  894. X      move.l d3,BLTDPT(a5) ; copy back
  895. X      move.w #0,BLTCON1(a5)
  896. X      move.w #$09f0,BLTCON0(a5)
  897. X      move.w #bsize,BLTSIZE(a5)
  898. X    jsr _LVODisownBlitter(a6) ; give it back
  899. X     rts
  900. X
  901. X; add two lattices, source pointed at by (a0) and dest by (a1)
  902. Xaddit: movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  903. X     lea _custom,a5
  904. X     move.l (a1)+,d2 ;start of bitplane1
  905. X     move.l (a1)+,d3 ;start of bitplane2
  906. X     move.l (a1),d4  ;start of bitplane3
  907. X     move.l (a0)+,d5 ;start of adding plane1
  908. X     move.l (a0),d6  ;start of adding plane2
  909. X    jsr _LVOOwnBlitter(a6) ; prepare to add identity to lattice
  910. X     move.l workingplane3(pc),d7 ; for carry
  911. X    jsr _LVOWaitBlit(a6)
  912. X      move.l d7,BLTDPT(a5) ; carry
  913. X      move.l d2,BLTAPT(a5) ; old first plane
  914. X      move.l d5,BLTBPT(a5) ; identity1
  915. X      move.w #0,BLTCON1(a5)
  916. X      move.w #$0dc0,BLTCON0(a5)
  917. X      move.w #modulo,BLTAMOD(a5)
  918. X      move.w #modulo,BLTBMOD(a5)
  919. X      move.w #modulo,BLTCMOD(a5)
  920. X      move.w #modulo,BLTDMOD(a5)
  921. X      move.w #$ffff,BLTAFWM(a5)
  922. X      move.w #$ffff,BLTALWM(a5)
  923. X      move.w #bsize,BLTSIZE(a5)
  924. X    jsr _LVOWaitBlit(a6)
  925. X      move.l d2,BLTDPT(a5) ; new first plane (assume old=0)
  926. X      move.l d2,BLTAPT(a5) ; old first plane
  927. X      move.l d5,BLTBPT(a5) ; identity1
  928. X      move.w #0,BLTCON1(a5)
  929. X      move.w #$0d3c,BLTCON0(a5)
  930. X      move.w #bsize,BLTSIZE(a5)
  931. X    jsr _LVOWaitBlit(a6)
  932. X      move.l d4,BLTDPT(a5) ; new third bit
  933. X      move.l d3,BLTAPT(a5) ; old second plane
  934. X      move.l d6,BLTBPT(a5) ; identity2
  935. X      move.l d7,BLTCPT(a5) ; old carry
  936. X      move.w #0,BLTCON1(a5)
  937. X      move.w #$0fe8,BLTCON0(a5)
  938. X      move.w #bsize,BLTSIZE(a5)
  939. X    jsr _LVOWaitBlit(a6)
  940. X      move.l d3,BLTDPT(a5) ; new second bit
  941. X      move.l d3,BLTAPT(a5) ; old second plane
  942. X      move.l d6,BLTBPT(a5) ; identity2
  943. X      move.l d7,BLTCPT(a5) ; old carry
  944. X      move.w #0,BLTCON1(a5)
  945. X      move.w #$0f96,BLTCON0(a5)
  946. X      move.w #bsize,BLTSIZE(a5)
  947. X    jsr _LVODisownBlitter(a6) ; give it back
  948. X    rts
  949. X
  950. Xcredits: ; display introductory comments    
  951. X    moveq.l #30,d2 ; length of lines
  952. X    moveq.l #15,d3  ; number of lines
  953. X    moveq.l #25,d4 ; starting row
  954. X    movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  955. X    lea.l mytext(pc),a3 ; start of text information
  956. X      movea.l rastport(pc),a1    
  957. X      moveq.w #7,d0
  958. X    jsr _LVOSetBPen(a6) ; set background pen color
  959. X      movea.l rastport(pc),a1    
  960. X      moveq.w #JAM2,d0
  961. X    jsr _LVOSetDrMd(a6) ; set drawing mode      
  962. X    bra startprint 
  963. Xmyprint:   movea.l rastport(pc),a1 ; rastport
  964. X           move.l d4,d1  ; starting row
  965. X           moveq.l #40,d0 ; starting column
  966. X         jsr _LVOMove(a6) ; locate pen
  967. X           movea.l rastport(pc),a1 ; rastport
  968. X           move.b (a3)+,d0 ; get color
  969. X           andi.l #7,d0 ; make sure color valid 
  970. X         jsr _LVOSetAPen(a6) ; set color
  971. X           movea.l rastport(pc),a1 ; rastport
  972. X           movea.l a3,a0 ; text location
  973. X           move.l d2,d0  ; length of line
  974. X         jsr _LVOText(a6) ; print line
  975. X         adda.l d2,a3 ; next line
  976. X         addi.l #8,d4 ; next row 
  977. Xstartprint: dbf d3,myprint      
  978. X     bsr waitformessage ; wait for key press
  979. X     movea.l GraphicsBase(pc),a6 ; graphics library address in a6
  980. X       movea.l rastport(pc),a1
  981. X       moveq.l #0,d0
  982. X     jsr _LVOSetRast(a6) ; clear screen
  983. X    rts
  984. Xmytext: ; initial number represents color
  985. X  dc.b 2,'                              '
  986. X  dc.b 2,'         BlitterSand          '
  987. X  dc.b 2,'                              '
  988. X  dc.b 6,'             by               '
  989. X  dc.b 2,'                              '
  990. X  dc.b 5,'        Michael Creutz        '
  991. X  dc.b 6,'     creutz@bnlux0.bnl.gov    '
  992. X  dc.b 5,'                              '
  993. X  dc.b 5,'<esc>, q  exit                '
  994. X  dc.b 5,'  p       pause               '
  995. X  dc.b 5,'  d       double modulo 8     '
  996. X  dc.b 5,'  a       pause after relax   '
  997. X  dc.b 1,'                              '
  998. X  dc.b 1,'    Press any key to start    '
  999. X  dc.b 2,'                              '
  1000. X   end
  1001. END_OF_FILE
  1002. if test 29043 -ne `wc -c <'BlitterSand.asm'`; then
  1003.     echo shar: \"'BlitterSand.asm'\" unpacked with wrong size!
  1004. fi
  1005. chmod +x 'BlitterSand.asm'
  1006. # end of 'BlitterSand.asm'
  1007. fi
  1008. if test -f 'BlitterSand.uu' -a "${1}" != "-c" ; then 
  1009.   echo shar: Will not clobber existing file \"'BlitterSand.uu'\"
  1010. else
  1011. echo shar: Extracting \"'BlitterSand.uu'\" \(4689 characters\)
  1012. sed "s/^X//" >'BlitterSand.uu' <<'END_OF_FILE'
  1013. Xbegin 700 BlitterSand
  1014. XM```#\P`````````!``````````````,5```#Z0```Q5(YS\^+'@`!$*Y```#E
  1015. XMPI/)3J[^VBA`2JP`K&8``!1![`!<3J[^@$ZN_HPCP````\)#^@.<<`!.KOW8$
  1016. XM(\````/&2H!G,D/Z`YEP`$ZN_=@CP````\I*@&<280``-B)Y```#RBQX``1.1
  1017. XMKOYB(GD```/&3J[^8G``2KD```/"9PQ.KO]\(GH#/DZN_H9,WWS\3G4CSP``E
  1018. XM!%)T!T7Z`YA@&"`\```=8"(\``$``DZN_SI*@&<``@`DP%'*_^8L>@,.0?H"=
  1019. XMRDZN_SHCP````WAG``'D0?H"B$ZN_S0CP```!!IG``'*($`CZ`!6```$(B!H_
  1020. XM`#(CR```!!X@:``$(^@`"```!"8CZ``,```$*B/H`!````0N!KD```&Z```$8
  1021. XM)@:Y```!N@``!"H&N0```;H```0N+'H"E"!Z`D+1_````"Q#^@)R<`A.KO]`Q
  1022. XM80`(R")Z`M!P`4ZN_JHB>@+&<`!.KOZ>(GH"O#`\`!`R/``+3J[_$"!Z`JPPR
  1023. XM/`$O,CP`"TZN_PH@>@*<,#P!+S(\`,9.KO\*('H"C#`\`!`R/`#&3J[_"B!ZN
  1024. XM`GPP/``0,CP`"TZN_PHB>@)L<`).KOZJ(GH"8C`\`!`R/``+3J[^O")Z`E(PC
  1025. XM/`$O,CP`"TZN_KPB>@)",#P!+S(\`,9.KOZ\(GH",C`\`!`R/`#&3J[^O&$`8
  1026. XM`-Q!^@(^0_H"(F$`!08(.@`%`D!F$D'Z`A)#^@(F80`%>&$`!&!@UD'Z`@!#R
  1027. XM^@(<80`%9D'Z`@QA``7.8!AA``(:"#H`!0(,9PQ!^@'^0_H!VF$`!NQA``7F/
  1028. XM"#H`!0'T9@9A``"D8-9A``!R0?H!O$/Z`=!A``4B80`$"F$``%Y!^@'`0_H!L
  1029. XMI&$`!K9A``!.0?H!N$/Z`91A``:F80``/F#N('H!>BQZ`29.KO^X('H`S$ZNG
  1030. XM_[XL>``$=`=%^@%X8!`@/```'6`B6B()9PA.KO\N4<K_[BYZ`7Y.=6$``7P(X
  1031. XM.@`%`6YF!F$``!Y@[DIY```$4&<$80``!$YU+'@`!"!Z`21.KOZ`+'@`!"!ZT
  1032. XM`1A.KOZ,2H!F`DYU(D`D*0`4-BD`&$ZN_H8,0P`;;P#_=`Q#`'%G`/]L#$,`[
  1033. XM<&8(('H`YDZN_H`,0P!D9@1A``,V#$,`868&1GD```103G4``````4``R```*
  1034. XM`"``````&````````````````_$````````````````!0`#(``\``````4``%
  1035. XMR``#!08````/```#J@```_$`````````````!`X`"```#_\```\``/`/\``/[
  1036. XM#P\`_P```````````````&=R87!H:6-S+FQI8G)A<GD`:6YT=6ET:6]N+FQIW
  1037. XM8G)A<GD`0FQI='1E<E-A;F0@+2T@/&5S8SX@=&\@97AI=`!T;W!A>BYF;VYT[
  1038. XM`````````````````````````````````````````````````````````````
  1039. XM```````````````````````L>O]N3J[^.$OY`-_P`"0Z_\`F.O_`*#K_P"HZ9
  1040. XM_\`L.O_`+CK_P$ZN_QPK10!4(`0K0`!0!H`````H*T``3`2`````4"M``$@[L
  1041. XM?````$([?!^6`$`[?``$`&0[?``$`&([?``$`&`[?``$`&8[?/__`$0[?/_^/
  1042. XM`$8[?"\2`%A.KO\<*T8`5"`$*T``4`:`````*"M``$P$@````%`K0`!(.WP?3
  1043. XMZ`!`.WPO$@!83J[_'"`$!H```!U:*T``4"`'!H```!U:*T``5"`%!H```!U:P
  1044. XM*T``3"`&!H```!U:*T``2#M\``(`0CM\'X``0#M\?_\`1CM\+Q(`6$ZN_QP@@
  1045. XM!`:````=6BM``%`@!@:````=6BM``%0K0`!((`4&@```'5HK0`!,.WP?:@!`J
  1046. XM.WPO$@!83J[_'"`$!H```!U:*T``4"`%!H```!U:*T``5"M``$P[?!T\`$`[F
  1047. XM?"\2`%A.KO\<*T0`5"M#`%`K1@!,*T<`2#M\````0CM\#^H`0#M\__\`1CM\_
  1048. XM+Q(`6$ZN_QPK0P!4*T,`4"M&`$P[?`T\`$`[?"\2`%A.KO\<*T<`5"M"`%`K"
  1049. XM0P!,*T4`2#M\#X``0#M\+Q(`6$ZN_QPK0P!4*T(`4"M%`$PK0P!(.WP/:@!`5
  1050. XM.WPO$@!83J[_'"M$`%0K1`!0*T<`3#M\#?P`0#M\+Q(`6$ZN_QPS[0`"```$T
  1051. XM3BM"`%0K0@!0*T4`3#M\#3P`0#M\+Q(`6$ZN_C).=2QZ_41.KOXX2_D`W_``S
  1052. XM)#K]EB8Z_98H.OV63J[_'"M$`%0K0P!0.WP```!".WP)\`!`.WP`!`!D.WP`P
  1053. XM!`!B.WP`!`!@.WP`!`!F.WS__P!$.WS__P!&.WPO$@!83J[_'"M#`%0K0@!0\
  1054. XM.WP)\`!`.WPO$@!83J[_'"M"`%0[?`$``$`[?"\2`%A.KOXR3G4L>ORV2_D`K
  1055. XMW_``)!@F$"@9*A%.KOXX3J[_'"M"`%`K1`!,.WP```!".WP,/`!`.WP`!`!D5
  1056. XM.WP`!`!B.WS__P!$.WS__P!&.WPO$@!83J[_'#/M``(```1.*T,`4"M%`$P[A
  1057. XM?````$([?`P\`$`[?"\2`%A.KO\<,"T``L%Y```$3DZN_C).=2QZ_#!+^0#?S
  1058. XM\``D&"80*!DJ$4ZN_CA.KO\<*T(`4"M$`%0[?````$([?`GP`$`[?``$`&0[J
  1059. XM?``$`&8[?/__`$0[?/__`$8[?"\2`%A.KO\<*T,`4"M%`%0[?````$([?`GPL
  1060. XM`$`[?"\2`%A.KOXR3G4L>OO`2_D`W_``)!!.KOXX3J[_'"M"`%0[?````$([E
  1061. XM?`'_`$`[?``$`&8[?"\2`%A.KOXR3G4L>ON*3J[^.$OY`-_P`"0Z^]PF.OO<X
  1062. XM*CK[X"PZ^^`N.OOD3J[_'"M%`%0K0@!0*T,`3"M'`$@[?````$([?`]8`$`[E
  1063. XM?``$`&0[?``$`&([?``$`&`[?``$`&8[?/__`$0[?/__`$8[?"\2`%A.KO\<8
  1064. XM*T8`5"M"`%`K0P!,*T<`2#M\````0CM\#\0`0#M\+Q(`6$ZN_QPK1P!4*T(`3
  1065. XM4"M#`$PK1P!(.WP```!".WP/`@!`.WPO$@!83J[_'#/M``(```1.*T4`4"M"-
  1066. XM`%0[?````$([?`GP`$`[?"\2`%A.KO\<*T8`4"M#`%0[?````$([?`GP`$`[+
  1067. XM?"\2`%A.KOXR3G4L>OJ(2_D`W_``)!DF&2@1*A@L$$ZN_C@N.OKD3J[_'"M'S
  1068. XM`%0K0@!0*T4`3#M\````0CM\#<``0#M\``0`9#M\``0`8CM\``0`8#M\``0`<
  1069. XM9CM\__\`1#M\__\`1CM\+Q(`6$ZN_QPK0@!4*T(`4"M%`$P[?````$([?`T\T
  1070. XM`$`[?"\2`%A.KO\<*T0`5"M#`%`K1@!,*T<`2#M\````0CM\#^@`0#M\+Q(`^
  1071. XM6$ZN_QPK0P!4*T,`4"M&`$PK1P!(.WP```!".WP/E@!`.WPO$@!83J[^,DYUZ
  1072. XM=!YV#W@9+'KYK$?Z`&(B>OG\<`=.KOZD(GKY\G`!3J[^GF```#(B>OGD(@1PM
  1073. XM*$ZN_Q`B>OG8$!L"@`````=.KOZJ(GKYR"!+(`).KO_$U\(&A`````A1R__.U
  1074. XM80#XBBQZ^50B>OFH<`!.KO\63G4"("`@("`@("`@("`@("`@("`@("`@("`@9
  1075. XM("`@("`@`B`@("`@("`@($)L:71T97)386YD("`@("`@("`@(`(@("`@("`@@
  1076. XM("`@("`@("`@("`@("`@("`@("`@("`&("`@("`@("`@("`@(&)Y("`@("`@A
  1077. XM("`@("`@("`@`B`@("`@("`@("`@("`@("`@("`@("`@("`@("`@(`4@("`@G
  1078. XM("`@($UI8VAA96P@0W)E=71Z("`@("`@("`&("`@("!C<F5U='I`8FYL=7@PL
  1079. XM+F)N;"YG;W8@("`@!2`@("`@("`@("`@("`@("`@("`@("`@("`@("`@(`4\J
  1080. XM97-C/BP@<2`@97AI="`@("`@("`@("`@("`@("`%("!P("`@("`@('!A=7-EC
  1081. XM("`@("`@("`@("`@("`@!2`@9"`@("`@("!D;W5B;&4@;6]D=6QO(#@@("`@L
  1082. XM(`4@(&$@("`@("`@<&%U<V4@869T97(@<F5L87@@("`!("`@("`@("`@("`@3
  1083. XM("`@("`@("`@("`@("`@("`@`2`@("!0<F5S<R!A;GD@:V5Y('1O('-T87)TP
  1084. XM("`@(`(@("`@("`@("`@("`@("`@("`@("`@("`@("`@("``3G$```/L````P
  1085. XM'``````````*````+````#P```!0````7@```&P```!X````D@```,@```#:4
  1086. XM````Z````/(```#^```!!@```0X```$8```!(@```2P```+L```#5````W0`3
  1087. XC``.:```#G@```ZH```9>```'8@``!XH```CZ`````````_+LL
  1088. X``
  1089. Xend
  1090. Xsize 3320
  1091. END_OF_FILE
  1092. if test 4689 -ne `wc -c <'BlitterSand.uu'`; then
  1093.     echo shar: \"'BlitterSand.uu'\" unpacked with wrong size!
  1094. fi
  1095. # end of 'BlitterSand.uu'
  1096. fi
  1097. echo shar: End of archive 1 \(of 1\).
  1098. cp /dev/null ark1isdone
  1099. MISSING=""
  1100. for I in 1 ; do
  1101.     if test ! -f ark${I}isdone ; then
  1102.     MISSING="${MISSING} ${I}"
  1103.     fi
  1104. done
  1105. if test "${MISSING}" = "" ; then
  1106.     echo You have the archive.
  1107.     rm -f ark[1-9]isdone
  1108. else
  1109.     echo You still need to unpack the following archives:
  1110.     echo "        " ${MISSING}
  1111. fi
  1112. ##  End of shell archive.
  1113. exit 0
  1114. -- 
  1115. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  1116. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  1117. Post requests for sources, and general discussion to comp.sys.amiga.
  1118.